local zhuohua = fk.CreateSkill {
  name = "emo__zhuohua",
}

zhuohua:addEffect("active", {
  anim_type = "support",
  prompt = "#emo__zhuohua",
  card_num = 0,
  target_num = 0,
  times = function (self, player)
    return 1 - player:usedSkillTimes(zhuohua.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(zhuohua.name, Player.HistoryPhase) < 1
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local ids = room:getNCards(4)
    room:moveCardTo(ids, Card.Processing, nil, fk.ReasonPut, zhuohua.name, nil, true, player)
    room:delay(500)

    local to_get = room:askToPoxi(player, {
      poxi_type = "emo__zhuohua_poxi", cancelable = false,
      data = {{ self.name, ids }},
    })
    local choices = {"emo__zhuohua_cishu", "emo__zhuohua_juli"}
    local choice = choices[2]
    if #to_get == 1 then
      choice = room:askToChoice(player, {skill_name = zhuohua.name, choices = choices, prompt = "#emo__zhuohua-choice"})
    elseif Fk:getCardById(to_get[1]).suit == Fk:getCardById(to_get[2]).suit then
      choice = choices[1]
    end
    room:setPlayerMark(player, "@@"..choice.."-turn", 1)

    room:moveCardTo(to_get, Player.Hand, player, fk.ReasonPrey, zhuohua.name)
    room:cleanProcessingArea(ids, zhuohua.name)
  end,
})

Fk:addPoxiMethod{
  name = "emo__zhuohua_poxi",
  card_filter = function(to_select, selected)
    if #selected < 2 then return true end
    return (Fk:getCardById(selected[1]).suit == Fk:getCardById(selected[2]).suit) ==
    (table.find(selected, function(id) return Fk:getCardById(id).suit == Fk:getCardById(to_select).suit end) ~= nil)
  end,
  feasible = function(selected)
    return #selected > 0
  end,
  default_choice = function(data)
    local cards = data[1][2]
    return table.filter(cards, function(id) return Fk:getCardById(id).suit == Fk:getCardById(cards[1]).suit end)
  end,
  prompt = function ()
    return Fk:translate("#emo__zhuohua-get")
  end,
}

zhuohua:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    return card and player:getMark("@@emo__zhuohua_cishu-turn") > 0
  end,
  bypass_distances = function(self, player, skill, card)
    return card and player:getMark("@@emo__zhuohua_juli-turn") > 0
  end,
})

Fk:loadTranslationTable{
  ["emo__zhuohua"] = "濯华",
  [":emo__zhuohua"] = "出牌阶段限一次，你可以亮出牌堆顶四张牌并选一项：<br>"..
  "①获得其中一种花色的牌，本回合你使用牌没有次数限制；<br>"..
  "②获得其中不同花色的牌，本回合你使用牌没有距离限制。",

  ["#emo__zhuohua"] = "濯华:亮出牌堆顶四张牌，获得其中花色相同或不同的牌",
  ["emo__zhuohua_poxi"] = "濯华",
  ["emo__zhuohua_cishu"] = "无次数限制",
  ["emo__zhuohua_juli"] = "无距离限制",
  ["#emo__zhuohua-get"] = "濯华：选择要获得的牌",
  ["#emo__zhuohua-choice"] = "濯华：获得你本回合获得的效果",
  ["@@emo__zhuohua_cishu-turn"] = "濯华:次数",
  ["@@emo__zhuohua_juli-turn"] = "濯华:距离",
}

return zhuohua
